#include<stdlib.h>
#include<unistd.h>
#include<fcntl.h>
#include<sys/stat.h>
#include<sys/types.h>
#include<errno.h>
#include<stdio.h>
#include<string.h>

int * Fibonacci(int n){
    int *arr = (int*)malloc(sizeof(int)*n);
    arr[0]=1;
    if(n<2){
        return arr;
    }
    else{
        
        int l=0,r=1;
        for(int i=1;i<n;++i){
            arr[i]=l+r;
            l=r;
            r= arr[i];

        }
    }
    return arr;

}

int main(int argc,char* argv[]){
    int numIN;
    scanf("%d",&numIN);
    if(numIN<=0) {
        printf("输入错误 n 应该大于0，当前n=%d \n",numIN);
        exit(0);
        }
    int fd = open(argv[1],O_WRONLY|O_CREAT);
    if(fd<0){
        perror("open error");
        return -1;
    }
    int *arr = Fibonacci(numIN);
    for(int i=0;i<numIN;++i){
        char val[20];
         sprintf(val,"%d",arr[i]);
        char * str = strcat(val,"\n");
        write(fd,str,strlen(str));
    }
    free(arr);
    close(fd);
    return 0;

}
